/**
 * 管理初始化
 */
var LogPurseCorpus = {
    id: "LogPurseCorpusTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
LogPurseCorpus.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '序号', field: 'id', visible: true, align: 'center', valign: 'middle',
                formatter: function (value, row, index) {
                    return index+1;
                }
            },
            {title: '目标用户手机号', field: 'userPhone', visible: true, align: 'center', valign: 'middle'},
            {title: '发起用户手机号', field: 'fromPhone', visible: true, align: 'center', valign: 'middle'},
            {title: '对应订单号', field: 'orderNo', visible: true, align: 'center', valign: 'middle'},
            {title: '操作前的数量', field: 'prePurseCorpus', visible: true, align: 'center', valign: 'middle'},
            {title: '变化的数量', field: 'purseCorpus', visible: true, align: 'center', valign: 'middle'},
            {title: '流水标志', field: 'purseCorpusType', visible: true, align: 'center', valign: 'middle',
                formatter:function(value,row,index){
                    var result;
                    switch(value){
                        case -1:
                            result = "减少";
                            break;
                        case 1:
                            result = "增加";
                            break;

                    }
                    return result;
                }
            },
            {title: '备注', field: 'remark', visible: true, align: 'center', valign: 'middle'},
            {title: '有效状态', field: 'dataFlag', visible: true, align: 'center', valign: 'middle'},
            {title: '创建时间', field: 'createTime', visible: true, align: 'center', valign: 'middle'},
            {title: '类型', field: 'type', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
LogPurseCorpus.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        LogPurseCorpus.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加
 */
LogPurseCorpus.openAddLogPurseCorpus = function () {
    var index = layer.open({
        type: 2,
        title: '添加',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/logPurseCorpus/logPurseCorpus_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看详情
 */
LogPurseCorpus.openLogPurseCorpusDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/logPurseCorpus/logPurseCorpus_update/' + LogPurseCorpus.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除
 */
LogPurseCorpus.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/logPurseCorpus/delete", function (data) {
            Feng.success("删除成功!");
            LogPurseCorpus.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("logPurseCorpusId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询列表
 */
LogPurseCorpus.search = function () {
    var queryData = {};
    queryData['orderNo'] = $("#orderNo").val();
    queryData['beginTime'] = $("#beginTime").val();
    queryData['endTime'] = $("#endTime").val();
    LogPurseCorpus.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = LogPurseCorpus.initColumn();
    var table = new BSTable(LogPurseCorpus.id, "/logPurseCorpus/list", defaultColunms);
    table.setPaginationType("server");
    LogPurseCorpus.table = table.init();
});
